import request from './request'
import type { User, PaginationParams, PaginationResponse } from '@/types'

export const userAPI = {
  getUsers: (params: PaginationParams & { username?: string; email?: string }): Promise<PaginationResponse<User>> => {
    return request.get('/users', { params })
  },
  
  getUser: (id: number): Promise<User> => {
    return request.get(`/users/${id}`)
  },
  
  createUser: (data: {
    username: string
    password: string
    email: string
    phone?: string
    role_ids?: number[]
  }): Promise<User> => {
    return request.post('/users', data)
  },
  
  updateUser: (id: number, data: {
    email: string
    phone?: string
    status: number
    role_ids?: number[]
  }): Promise<User> => {
    return request.put(`/users/${id}`, data)
  },
  
  deleteUser: (id: number): Promise<void> => {
    return request.delete(`/users/${id}`)
  },
  
  changePassword: (id: number, newPassword: string): Promise<void> => {
    return request.put(`/users/${id}/password`, { new_password: newPassword })
  }
}